import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/ui/basice/base_navigation_widget.dart';
import 'package:core_package/core_package.dart';
import 'package:flutter_app_unionad/ui/my_facility/make_an_appointment_install_page.dart';
import 'package:flutter_app_unionad/ui/workbench/widget/work_activate_widget.dart';
import 'package:flutter_app_unionad/ui/workbench/widget/work_search_widget.dart';
import 'package:flutter_app_unionad/ui/workbench/widget/work_take_list_widget.dart';

class WorkbenchPage extends StatefulWidget {
  @override
  _WorkbenchPageState createState() => _WorkbenchPageState();
}

class _WorkbenchPageState extends State<WorkbenchPage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
  TabController? _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TabController(length: 4, vsync: this);
  }


  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();

    _controller?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BaseNavigationWidget(
      child: buildContent(),
      title: '工作台',
      needScrollView: false,
      haveReturn: false,
    );
  }

  Widget buildContent() {
    return Container(
      child: Column(
        children: [
          buildTitleWidget(),
          MySizeBox(height: 5,),
          Expanded(child: buildPageViewWidget())
        ],
      ),
    );
  }

  Widget buildPageViewWidget() {

    return TabBarView(
      children: [
        WorkTakeListWidget(),
        WorkActivateWidget(),
        MakeAnAppointmentInstallPage(needPhone: true),
        WorkSearchWidget(),
      ],
      controller: _controller,
    );
  }

  Widget buildTitleWidget() {
    return Container(
      height: 50.px,
      width: double.infinity,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(5.px),
      ),
      child: TabTitleWidget(
        titleList: ['待安装', '激活', '预约安装', '查询'],
        tabController: _controller,
        labelColor: MyColors.color_245_174_41,
        isScrollable: false,
        padding: EdgeInsets.zero,
        indicatorColor: MyColors.color_245_174_41,
        labelPadding: EdgeInsets.zero,
        onTop: (index) {
          _controller?.animateTo(index);
        },
      ),
    );
  }
}
